<?php
declare (strict_types=1);

namespace app\exam\model\admin;

use app\admin\logic\user\Account;
use app\common\model\BaseModel;

/**
 * 后台管理
 */
class QuestionTopicMaterial extends BaseModel
{

    /**
     * 表名
     *
     * @var string
     */
    protected $name = 'exam_question_topic_material';
    /**
     * 定义表主键
     *
     * @var string
     */
    protected $pk = 'id';
    /**
     * 时间显示格式
     *
     * @var string
     */
    protected $dateFormat = 'Y-m-d H:i';
    /**
     * 定义字段类型
     *
     * @var array
     */
    protected $type = [
        'id'    => 'integer',
        'point' => 'json'
    ];

    /**
     * 定义试题类型
     *
     * @var string[]
     */
    protected $typeOptions = [
        1 => '单选',
        2 => '判断',
        3 => '多选',
        4 => '不定项选择',
        8 => '简答',
    ];

    /**
     * 试题类型
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2020/11/25
     *
     * @param $value
     * @param $data
     * @return string
     */
    public function getQuestionTypeTextAttr($value, $data)
    {
        return $this->typeOptions[$data['question_type']] ?? '';
    }

    /**
     * 试题难度名称
     * Author: Martinsun <syh@sunyonghong.com>
     * Date: 2020/11/25
     *
     * @return \think\model\relation\BelongsTo
     */
    public function difficultyTitle()
    {
        return $this->belongsTo(QuestionDifficult::class, 'difficulty')->bind(['difficulty_title' => 'title']);
    }
}
